package chapter06

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test
 * Package: chapter06
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-06-25
 *          Time: 20:26
 */

object Test03_High {

  def main(args: Array[String]): Unit = {
    def f(n: Int): Int = {
      println("f调用")
      n + 1
    }

    f(1)

    //函数的高阶用法
    //1.函数作为值进行传递
    val f1 = f _
    val f2: Int => Int = f
    f1(1)
    f2(2)

    //2.函数作为参数传递
    def of(func: (Int, Int) => Int, a: Int, b: Int): Int = {
      func(a, b)
    }

    def add(a: Int, b: Int): Int = {
      a + b
    }

    of(add, 12, 34)
    of((a, b) => a + b, 123, 12)
    of(_ + _, 12, 43)
    //3.函数作为返回值传递
    def f5():Int =>Unit = {
      def f6(a:Int):Unit = {
        println("f6被调用" + a)
      }
      f6
    }

    val f6 = f5()
    println(f5())
    println(f6(23))
  }

}
